import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import java.awt.image.ComponentSampleModel;
import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.LayoutStyle;
//import java.awt.*;
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ISS_SIMD_FIR_form.java
 *
 * Created on 01-May-2009, 19:49:59
 */


/**
 * This code was edited or generated using CloudGarden's Jigloo
 * SWT/Swing GUI Builder, which is free for non-commercial
 * use. If Jigloo is being used commercially (ie, by a corporation,
 * company or business for any purpose whatever) then you
 * should purchase a license for each developer using Jigloo.
 * Please visit www.cloudgarden.com for details.
 * Use of Jigloo implies acceptance of these licensing terms.
 * A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
 * THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
 * LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
 */
/**
 *
 * @author kpatel
 */
@SuppressWarnings("unused")
public class ISS_SIMD_FIR_form extends javax.swing.JFrame {

	{
		//Set Look & Feel
		try {
			javax.swing.UIManager.setLookAndFeel("com.jgoodies.looks.plastic.Plastic3DLookAndFeel");
		} catch(Exception e) {
			e.printStackTrace();
		}
	}


	/** Creates new form ISS_SIMD_FIR_form */
	public ISS_SIMD_FIR_form() {
		initComponents();
	}

	/** This method is called from within the constructor to
	 * initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
	// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
	private void initComponents() {

		label_rows = new javax.swing.JLabel();
		textfield_rows = new javax.swing.JTextField();
		button_OK = new javax.swing.JButton();
		button_cancel = new javax.swing.JButton();
		button_clearall = new javax.swing.JButton();
		textfield_columns = new javax.swing.JTextField();
		label_columns = new javax.swing.JLabel();
		label_taps = new javax.swing.JLabel();
		label_samples = new javax.swing.JLabel();
		label_channels = new javax.swing.JLabel();
		textfield_taps = new javax.swing.JTextField();
		textfield_samples = new javax.swing.JTextField();
		textfield_channels = new javax.swing.JTextField();
		label_RAM = new javax.swing.JLabel();
		textfield_RAM = new javax.swing.JTextField();

		setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

		label_rows.setText("Enter no of rows for CFU array");
		{
			Button_browse = new JButton();
			Button_browse.setText("Browse");
			Button_browse.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					Button_browseActionPerformed(evt);
				}
			});
		}

		button_OK.setText("OK");
		button_OK.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				button_OKActionPerformed(evt);
			}
		});

		button_cancel.setText("Cancel");
		button_cancel.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				button_cancelActionPerformed(evt);
			}
		});

		button_clearall.setText("Clear all");
		button_clearall.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				button_clearallActionPerformed(evt);
			}
		});

		label_columns.setText("Enter no of columns for CFU array");
		{
			TextField_filepath = new JTextField();
		}
		{
			Label_filepath = new JLabel();
			Label_filepath.setText("Enter the file path to load RAM");
		}

		label_taps.setText("Enter no of taps in  FIR filter");

		label_samples.setText("Enter no of samples to process");

		label_channels.setText("Enter no of channels you want process in parallel");

		label_RAM.setText("Enter the size of RAM");

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
		getContentPane().setLayout(layout);
		layout.setVerticalGroup(layout.createSequentialGroup()
			.addContainerGap(20, 20)
			.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
			    .addComponent(textfield_rows, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
			    .addComponent(label_rows, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
			.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
			.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
			    .addComponent(textfield_columns, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
			    .addComponent(label_columns, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
			.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
			.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
			    .addComponent(textfield_taps, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
			    .addComponent(label_taps, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
			.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
			.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
			    .addComponent(textfield_samples, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
			    .addComponent(label_samples, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
			.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
			.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
			    .addComponent(textfield_channels, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
			    .addComponent(label_channels, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
			.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
			.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
			    .addComponent(textfield_RAM, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
			    .addComponent(label_RAM, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
			.addGap(7)
			.addGroup(layout.createParallelGroup()
			    .addGroup(GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
			        .addComponent(Button_browse, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
			        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED))
			    .addGroup(layout.createSequentialGroup()
			        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
			        .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
			            .addComponent(TextField_filepath, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
			            .addComponent(Label_filepath, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))))
			.addGap(0, 98, Short.MAX_VALUE)
			.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
			    .addComponent(button_OK, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
			    .addComponent(button_cancel, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
			    .addComponent(button_clearall, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
			.addContainerGap(37, 37));
		layout.setHorizontalGroup(layout.createSequentialGroup()
			.addContainerGap()
			.addGroup(layout.createParallelGroup()
			    .addGroup(GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
			        .addComponent(label_channels, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
			        .addGap(12)
			        .addGroup(layout.createParallelGroup()
			            .addGroup(layout.createSequentialGroup()
			                .addComponent(TextField_filepath, GroupLayout.PREFERRED_SIZE, 201, GroupLayout.PREFERRED_SIZE)
			                .addGap(0, 0, Short.MAX_VALUE))
			            .addGroup(GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
			                .addGroup(layout.createParallelGroup()
			                    .addComponent(textfield_rows, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 54, GroupLayout.PREFERRED_SIZE)
			                    .addGroup(GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
			                        .addComponent(textfield_RAM, GroupLayout.PREFERRED_SIZE, 44, GroupLayout.PREFERRED_SIZE)
			                        .addGap(10))
			                    .addGroup(GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
			                        .addComponent(textfield_channels, GroupLayout.PREFERRED_SIZE, 44, GroupLayout.PREFERRED_SIZE)
			                        .addGap(10))
			                    .addGroup(GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
			                        .addComponent(textfield_samples, GroupLayout.PREFERRED_SIZE, 44, GroupLayout.PREFERRED_SIZE)
			                        .addGap(10))
			                    .addGroup(GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
			                        .addComponent(textfield_taps, GroupLayout.PREFERRED_SIZE, 44, GroupLayout.PREFERRED_SIZE)
			                        .addGap(10))
			                    .addGroup(GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
			                        .addComponent(textfield_columns, GroupLayout.PREFERRED_SIZE, 44, GroupLayout.PREFERRED_SIZE)
			                        .addGap(10)))
			                .addGap(0, 39, Short.MAX_VALUE)
			                .addComponent(button_clearall, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
			                .addGap(52)))
			        .addGap(80))
			    .addGroup(layout.createSequentialGroup()
			        .addGap(75)
			        .addGroup(layout.createParallelGroup()
			            .addGroup(GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
			                .addComponent(label_columns, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
			                .addGap(0, 296, Short.MAX_VALUE))
			            .addGroup(layout.createSequentialGroup()
			                .addPreferredGap(label_columns, Label_filepath, LayoutStyle.ComponentPlacement.INDENT)
			                .addGroup(layout.createParallelGroup()
			                    .addGroup(GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
			                        .addComponent(Label_filepath, GroupLayout.PREFERRED_SIZE, 408, GroupLayout.PREFERRED_SIZE)
			                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
			                        .addComponent(Button_browse, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
			                        .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
			                    .addGroup(GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
			                        .addGroup(layout.createParallelGroup()
			                            .addGroup(layout.createSequentialGroup()
			                                .addPreferredGap(Label_filepath, label_taps, LayoutStyle.ComponentPlacement.INDENT)
			                                .addGroup(layout.createParallelGroup()
			                                    .addGroup(GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
			                                        .addComponent(label_taps, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
			                                        .addGap(11))
			                                    .addGroup(layout.createSequentialGroup()
			                                        .addGap(38)
			                                        .addGroup(layout.createParallelGroup()
			                                            .addComponent(label_RAM, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 118, GroupLayout.PREFERRED_SIZE)
			                                            .addGroup(GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
			                                                .addGap(22)
			                                                .addComponent(button_OK, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
			                                                .addGap(66))))))
			                            .addGroup(GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
			                                .addComponent(label_samples, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
			                                .addGap(7))
			                            .addGroup(GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
			                                .addComponent(label_rows, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
			                                .addGap(10)))
			                        .addComponent(button_cancel, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
			                        .addGap(0, 245, Short.MAX_VALUE)))))))
			.addContainerGap(180, 180));

		pack();
	}// </editor-fold>//GEN-END:initComponents

	private void button_clearallActionPerformed(java.awt.event.ActionEvent evt) 
	{//GEN-FIRST:event_button_clearallActionPerformed
		// This function clear all the fields of the form.
		//textfield_rows.setText("");
		initComponents();

	}//GEN-LAST:event_button_clearallActionPerformed

	private void button_OKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_button_OKActionPerformed
		/* This code performs the basic calculation before mapping application
         to the array
		 */
		//JOptionPane.showMessageDialog(null,"Jai Sairam..The program started 2...!");
		ISS_SIMD_FIR_16points_256samples1 fir_simd1 = new ISS_SIMD_FIR_16points_256samples1();
		
		
		fir_simd1.no_cfu_row_int = Integer.parseInt(textfield_rows.getText());
		fir_simd1.no_cfu_column_int = Integer.parseInt(textfield_columns.getText());
		fir_simd1.no_taps_int = Integer.parseInt(textfield_taps.getText());
		fir_simd1.no_samples_int = Integer.parseInt(textfield_samples.getText());
		fir_simd1.no_channels_int = Integer.parseInt(textfield_channels.getText());
		fir_simd1.ram_size = Integer.parseInt(textfield_RAM.getText());
		fir_simd1.file_path = TextField_filepath.getText();
		JOptionPane.showMessageDialog(null,fir_simd1.file_path);
		//C:\Users\Kunjan Patel\workspace\FIR_16taps_256samples\src\test.txt (laptop)
		//C:\Users\kpatel\workspace\FIR_16taps_256samples\src\test.txt (Desktop)

		fir_simd1.total_cfu = fir_simd1.no_cfu_column_int * fir_simd1.no_cfu_row_int;
		fir_simd1.no_cfu_per_channel =  fir_simd1.total_cfu / fir_simd1.no_channels_int;
		fir_simd1.unused_cfu = fir_simd1.total_cfu -
		(fir_simd1.no_cfu_per_channel * fir_simd1.no_channels_int);

		//Enter logic to check sufficient RAM is available or not

		JOptionPane.showMessageDialog(null, "no_cfu_per_channel = " +
				fir_simd1.no_cfu_per_channel+"\nchannels = "+
				fir_simd1.no_channels_int+"\nunused = " + fir_simd1.unused_cfu );

		
		//fir_simd1.Create_Cfu_Array();
		//fir_simd1.Create_RAM();

		/*
		 * Here, flexibility can be added by including arguments which can take taps of FIR filter and no of samples to process 
		 */
		
		fir_simd1.run_fir_16taps_256_samples_4channels();

	}//GEN-LAST:event_button_OKActionPerformed

	private void button_cancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_button_cancelActionPerformed
		// Exit the application if cancel button is pressed

		dispose();
	}//GEN-LAST:event_button_cancelActionPerformed

	/**
	 * @param args the command line arguments
	 */
	public static void main(String args[]) {
		java.awt.EventQueue.invokeLater(new Runnable() {
			public void run() {
				new ISS_SIMD_FIR_form().setVisible(true);
			}
		});
	}
	
	private void Button_browseActionPerformed(ActionEvent evt) {
		System.out.println("Button_browse.actionPerformed, event="+evt);
		//TODO add your code for Button_browse.actionPerformed
	}

	// Variables declaration - do not modify//GEN-BEGIN:variables
	private javax.swing.JButton button_OK;
	private javax.swing.JButton button_cancel;
	private javax.swing.JButton button_clearall;
	private javax.swing.JLabel label_RAM;
	private javax.swing.JLabel label_channels;
	private javax.swing.JLabel label_columns;
	private javax.swing.JLabel label_rows;
	private javax.swing.JLabel label_samples;
	private javax.swing.JLabel label_taps;
	private javax.swing.JTextField textfield_RAM;
	private javax.swing.JTextField textfield_channels;
	private JTextField TextField_filepath;
	private JButton Button_browse;
	private JLabel Label_filepath;
	private javax.swing.JTextField textfield_columns;
	private javax.swing.JTextField textfield_rows;
	private javax.swing.JTextField textfield_samples;
	private javax.swing.JTextField textfield_taps;
	// End of variables declaration//GEN-END:variables

}
